<template>

	<view style="height: 100vh;background-color:#7571e6;overflow-y: scroll;">
		<report :wqid="wqid" v-if="showreport" @restart="restart"></report>
		<view v-if="!showreport">
			<u-navbar title="企业健康体检"
				:background="{'background':'linear-gradient(180deg,#7571e6,#7571e6)','color':'#fff'}">
			</u-navbar>

			<question ref="question" :wqdata.sync="qdata" v-if="qdata.length>0" @wancheng="wancheng"></question>
			<!-- <fixedTool :data="list" :isIcon="isIcon" :scrollTop="scrollTop" @tapBar="tapToolsBar" @tapShow="tapShow"
			:isslotcontent="true" :show="toolshow">
		
		</fixedTool> -->
			<view style="position: fixed; width: 100rpx;height: 100rpx;border-radius: 50%;bottom: 20rpx;
			right: 20rpx;background-color: #ffc92a;box-shadow: 0 0 20rpx rgba(0, 0, 0, 0.5);text-align: center;"
				@click="showpop=true">
				<u-icon name="question" size="55" style="margin-top: 20rpx;"></u-icon>
			</view>
			<u-popup v-model="showpop" mode="bottom" border-radius="14" @close="toolshow=false">
				<view style="width: 100%;text-align: center;font-weight: bolder;padding: 20rpx 0;font-size: 28rpx;">回答详情
				</view>
				<view style="max-height: 600rpx;overflow-y: scroll;padding: 20rpx;width: 100%;">
					<view v-for="(item,index) in qdata" style="padding-top: 20rpx;" :key="index">
						<view style="padding-bottom: 10rpx;">
							{{"第"+(index+1)+"部分："}}{{item.title}}
						</view>
						<view style="width: 100%;overflow-x: scroll;">
							<view v-for="(wenti,wtindex) in item.questiondata" :key="wtindex"
								@click="towenti(index,wtindex)" style="display:inline-block;">
								<view
									style="border-radius: 10rpx; width: 80rpx;height: 80rpx;margin-bottom: 20rpx;text-align: center; margin-right: 20rpx;font-size: 24rpx;line-height: 80rpx;"
									:class="[ishuida(wenti)?'bg-green':'bg-gray']">{{wtindex+1}}题</view>
							</view>
						</view>
					</view>
				</view>
			</u-popup>
			<view class="organization combg" v-if="wqid">
				<view class="savebutton" @click="showreport=true">查看结果</view>
			</view>
		</view>
	</view>
</template>

<script>
	import questions from '@/components/questions/questions.vue';
	import fixedTool from '@/components/fixed-tools.vue';
	import uPopup from "@/uview-ui/components/u-popup/u-popup.vue"
	import report from "../report/report.vue"
	import {
		qdata
	} from '@/components/questions/qdata.js'
	import {
		http,
		Method
	} from "@/utils/request.js";
	import storage from "@/utils/storage.js";
	export default {
		components: {
			question: questions,
			fixedTool: fixedTool,
			uPopup,
			report
		},
		data() {
			return {
				wqid: 25,
				showreport: false,
				toolshow: false,
				showpop: false,
				list: [{
					icon: '_icon-loading',
					num: 0
				}, {
					icon: '_icon-search',
					num: 0
				}],
				isIcon: {
					down: 'cicon-unfold-less',
					top: 'list-dot',
					up: 'list-dot'
				},
				scrollTop: 0,
				qdata: []
			}
		},
		onLoad(option) {
			this.qdata = qdata;

			console.log("qdata", qdata)
		},
		methods: {
			restart() {
				this.showreport = false;
			},
			towenti(index, wentiindex) {
				console.log("towenti")
				this.$refs["question"].setindex(index, wentiindex)
				this.showpop = false;
			},
			ishuida(item) {
				let answers = item.answers;
				let huida = false;
				answers.forEach(ii => {
					if (ii.answerchecked) {
						huida = true;
					}
				});
				return huida;
			},
			tapShow(isshow) {
				this.showpop = isshow;
			},
			tapToolsBar(item, index) {

			},
			async wancheng(list) {
				console.log("wancheng", list)
				let user = storage.getUserInfo();
				let mlaform = uni.getStorageSync("mlaform");
				let params = {
					enterpriseType: mlaform["sex"],
					enterpriseDate: mlaform["shijian"],
					enterpriseScale: mlaform["guimo"],
					enterpriseStage: mlaform["jieduan"],
					data: list,
					name: mlaform.name
				}
				uni.showLoading({
					title: "计算中",
					mask: true
				});
				console.log("*********************", JSON.stringify(params))
				let res = await http.request({
					url: "lili/questionnaire",
					method: Method.POST,
					needToken: false,
					data: params,
				});
				uni.hideLoading()
				let data = res.data.result || [];
				this.wqid = data.id;
				this.showreport = true;
				// uni.setStorageSync("oldqdata", this.qdata)
				// uni.redirectTo({
				// 	url: "/pages/wenjua/report/report?id=" + data.id
				// })
			}
		}
	}
</script>

<style scoped>
	page {
		background-color: #3f48cc;
	}
	.savebutton {
			width: 622rpx;
			/* line-height: 90rpx; */
			color: #594e3f;
			font-size: 32rpx;
			font-weight: 700;
			/* margin: 70rpx auto; */
			text-align: center;
	/* 		background: url(../img/savebtn.png) no-repeat 50%/100%; */
		}
</style>
